// 登录接口

import { post } from "@/util/request";
import { Dialog } from '@varlet/ui'
const login = async ({
    url = String,
    params = Object,
    success = Function,
    error = Function,
    complete = Function,
}) => {
    try {
        const res = await post(url, {
            ...params
        })
        if (res.status === "0000") {
            success(res.data);
        } else {
            error(res)
            Dialog({
                title: '登录失败',
                message: res.message,
            })
        }

    } catch (error) {
        // error(error)
        Dialog({
            title: '提示',
            message: "网络请求错误",
        })
    } finally {
        complete()
    }
}
const register = async ({
    url = String,
    params = Object,
    success = Function,
    error = Function,
    complete = Function,
}) => {
    try {
        const res = await post(url, {
            ...params
        })
        if (res.status === "0000") {
            success(res.data);
        } else {
            error(res)
            Dialog({
                title: '注册失败',
                message: res.message,
            })
        }

    } catch (error) {
        Dialog({
            title: '提示',
            message: "网络请求错误",
        })
    } finally {
        complete()
    }
}
const updateInfo = async ({
    url = String,
    params = Object,
    success = Function,
    error = Function,
    complete = Function,
}) => {
    try {
        const res = await post(url, {
            ...params
        })
        if (res.status === "0000") {
            success(res.data);
        } else {
            error(res)
            Dialog({
                title: '更新失败',
                message: res.message,
            })
        }

    } catch (error) {
        Dialog({
            title: '提示',
            message: "网络请求错误",
        })
    } finally {
        complete()
    }
}

// 根据自己的id去查找 自己的信息
const queryUserInfo = async ({
    url = String,
    params = Object,
    success = Function,
    error = Function,
    complete = Function,
}) => {
    try {
        const res = await post(url, {
            ...params
        })
        if (res.status === "0000") {
            success(res.data);
        } else {
            error(res)
            Dialog({
                title: '提示',
                message: res.message,
            })
        }

    } catch (error) {
        Dialog({
            title: '提示',
            message: "网络请求错误",
        })
    } finally {
        complete()
    }
}

export {
    login, register,updateInfo,queryUserInfo
}